/*-----------------------------------------------------------------------------
* @Description:     报名-报名详情
* @Version:         1.0.0
* @author:          gts(616603151@qq.com)
* @date             2017.11.14
* ==NOTES:=============================================
* 
* ---------------------------------------------------------------------------*/
$(function(){
    /**
     * 初始化提示信息、验证表单
     */
    Pagination(1);

    /**
     * 分页
     */
    $('#pageLimit').bootstrapPaginator({
        //currentPage: 3,
        totalPages: $('.pageDataCount').val(),
        size: "small",
        bootstrapMajorVersion: 3,
        alignment: "right",
        numberOfPages: 5,
        itemTexts: function (type, page, current) {
            switch (type) {
                case "first": return "首页";
                case "prev": return "<";
                case "next": return ">";
                case "last": return "末页";
                case "page": return page;
            }
        },
        onPageClicked: function (event, originalEvent, type, page) {
            var
                form = $(".J_searchForm").serializeObject();

            Pagination(page, form);  
        }
    });
     /**
     * 分页刷标题
     */
    function Pagination(page, extraData){

        var
            currentPage = page,            
            str1 = '',
            str2 = '',
            id = $("input[name='assessId']").val(),
            data = {
                pageNo: currentPage,
                assessId: id
            };
        jQuery.extend(data, extraData);

        $.ajax({
            type: jQuery.url.CheckManagement.detailContent.type,
            url: jQuery.url.CheckManagement.detailContent.url,
            contentType: "application/x-www-form-urlencoded; charset=utf-8",
            data: data,     //JSON.stringify
            dataType: "json",
            success: function (rs) {
               if( rs.code == 0){ 
                    $('#pageLimit').bootstrapPaginator({
                        totalPages: rs.pageDataCount
                    });
                    $('#J_title').empty();
                    str1 += '<th>姓名</th><th>年级</th>';
                    $.each(rs.tempList, function(index, item){
                        str1 += '<th data-id="'+item.tempId +'">'+ item.tempName +'</th>'
                    });
                    str1 += '<th>教研组</th>';
                    $.each(rs.tempList, function(index, item){
                        str1 += '<th data-id="'+item.tempId +'">'+ item.tempName +'</th>'
                    });
                    $('#J_title').append(str1);
                    
                    $('#J_template').empty();
                    $.each(rs.list, function(trIndex, trItem){
                        str2 += '<tr><td>'+trItem.name+'</td>';
                        str2 += '<td>'+trItem.grade+'</td>';
                        $.each(trItem.gradeResult,function(index, item){  
                            str2 += '<td>'+ item.result +'</td>';
                        });
                        str2 += '<td>'+trItem.subject+'</td>';
                        $.each(trItem.subjectResult,function(index, item){  
                            str2 += '<td>'+ item.result +'</td>';
                        });
                        str2 += '</tr>';
                    });
                    $('#J_template').append(str2);
                }else{                
                    Alert('提示信息', '返回参数错误');
                }
            },
            error: function (message) {
                Alert('提示信息', '请求发送失败！');
            }
        });
    }
     
    /**
     * 列表点击搜索事件
     * @param  {[type]} ){                     }
     * @return {[type]}     [description]
     */
    $(".J_search").click(function(){
        var
            form = $(".J_searchForm").serializeObject();

       
        Pagination(1, form);
    });

})  

   